// 1.引入router路由实例
import router from './router'
import store from './store'
const whiteList = ['/login', '/404']

// 2.启用路由跳转前置守卫
router.beforeEach((to, from, next) => {
  // next()

  const { token } = store.getters

  if (token) {
    // 如果token存在，判断是否去登录页
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    // 如果没有token，判断是否去白名单页面
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})

